<template>
  <div>
    <p>基础信息</p>
    <p v-for="(i, j) in params"  :key="i">
      {{j}}：{{i}}
    </p>
    <p>审批信息</p>
    <table>
      <tr v-for="z in task.audit_records" :key="z">
        <td>{{z.username}}</td>
        <td>{{z.is_agree}}</td>
        <td>{{z.add_time}}</td>
        <td>{{z.reason}}</td>
      </tr>
    </table>
    <van-radio-group v-model="agree">
      <van-radio name="1">同意</van-radio>
      <van-radio name="0">不同意</van-radio>
    </van-radio-group>
    <van-field  label='情况详情' v-model='reason'/>
    <van-button @click='submit'>提交</van-button>
  </div>
</template>

<script>
import myaxios from 'axios'
export default {
  name: "audit",
  data(){
    return{
      tid:this.$route.query.id,
      task:{},
      params:{},
      agree:1,
      reason:'',
      userid:localStorage.getItem('userid'),
      name:localStorage.getItem('username')
    }
  },
  methods:{
    getTask(){
      myaxios({url:'http://127.0.0.1:5000/tssk', method:'post', data:{'id':this.tid}})
          .then(res=>{
            console.log(res.data)
            this.task = res.data.task
            this.params = JSON.parse(res.data.task['params'])
          })
    },
    submit(){
      myaxios({url:'http://127.0.0.1:5000/taskrecordM', method:'post', data:{'taskid':this.tid, 'userid':4, 'name':this.name, 'agree': this.agree, 'reason':this.reason}})
          .then(res=>{
            console.log(res.data)
          })
    }
  },
  mounted() {
    this.getTask()
  }
}
</script>

<style scoped>

</style>